const path = require("path");
const express = require("express");
const focusList = require("./data/focus.json")
const likeList = require("./data/like.json")
const app = express()

app.use(express.static(__dirname));
app.get("/focusList",(req,res)=>{
    res.json({
        ok:1,
        focusList
    })
})

app.get("/likeList",(req,res)=>{
    console.log('55',req.query);

    // query:pageSize:每页显示的条数 pageNo：页码
    const pageSize = (req.query.pageSize || 6)*1
    const pageNo = (req.query.pageNo || 1)*1

    // 总页数
    const pageSum = Math.ceil(likeList.length/pageSize);

    if(pageNo>pageSum) pageNo = pageSum

    // 起始位置
    const star = (pageNo - 1)*pageSize;
    res.json({
        ok:666,
        likeList:likeList.slice(star,star+pageSize),
        pageNo,
        pageSum
    })
})

app.listen(8888,()=>{
    console.log("成功啦");
})